﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using Core;

namespace DAL
{
  public class LoaiSPDAL
    {
      public static List<LoaiSP> LayTatCa()
      {
          try
          {
              return CBO.FillCollection<LoaiSP>(DataProvider.Instance.ExecuteReader("LoaiSP_LayTatCa"));
          }
          catch
          {
              
              return new List<LoaiSP>();
          }
      }
      public static bool Them(LoaiSP l)
      {
          try
          {
              object rd = DataProvider.Instance.ExecuteNonQueryWithOutput("@IDLoaiSP", "LoaiSP_Them", l.IDLoaiSP, l.TenLoaiSP, l.MoTa);
              return Convert.ToInt32(rd) > 0;
          }
          catch
          {
              
              return false;
          }
      }
      public static bool Sua(LoaiSP l)
      {
          try
          {
              int rd = DataProvider.Instance.ExecuteNonQuery("LoaiSP_Sua", l.IDLoaiSP, l.TenLoaiSP, l.MoTa);
              return Convert.ToInt32(rd) > 0;
          }
          catch
          {

              return false;
          }
      }
      public static bool Xoa(string Id)
      {
          try
          {
              int rs = DataProvider.Instance.ExecuteNonQuery("LoaiSP_Xoa",Convert.ToInt32(Id));
              return Convert.ToInt32(rs) > 0;
          }
          catch
          {

              return false;
          }
      }
       public static LoaiSP LayID(string Id)
        {
            try
            {
                return CBO.FillObject<LoaiSP>(DataProvider.Instance.ExecuteReader("LoaiSP_LayID", Convert.ToInt32(Id)));
            }
            catch
            {
                return new LoaiSP();
            }
        }
       public static List<LoaiSP> TimKiemLoaiSP(string ten)
       {
           try
           {
               return CBO.FillCollection<LoaiSP>(DataProvider.Instance.ExecuteReader("LoaiSP_TimKiemSP", ten));
           }
           catch
           {

               return new List<LoaiSP>() ;
           }
       }
      
    }
}
